#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${package}.demo.controller;

import ${package}.demo.service.ProductService;
import com.ucarinc.framework.common.ConResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author liuxw
 * @date 2019/3/29
 * @since 1.0
 */
@Controller
public class HomeController {

    @Autowired
    private ProductService productService;

    @RequestMapping("/")
    public String index(){
        return "index";
    }
    @RequestMapping("/login")
    @ResponseBody
    public ConResult login(HttpServletRequest request, HttpServletResponse response){

        Cookie cookie = new Cookie("react", "react-login");
        cookie.setPath("/");
        cookie.setMaxAge(60 * 60 * 2);
        response.addCookie(cookie);

        return ConResult.success();
    }

    @RequestMapping("index1")
    public String index1(){
        return "index1";
    }

    @RequestMapping("/logout")
    @ResponseBody
    public ConResult logout(HttpServletRequest request, HttpServletResponse response) {
        Cookie[] cookieArray = request.getCookies();
        for (Cookie cookie : cookieArray) {
            if ("react".equals(cookie.getName())) {
                //设置cookie有效时间为0
                cookie.setMaxAge(0);
                //不设置存储路径
                cookie.setPath("/");
                response.addCookie(cookie);
            }
        }
        return ConResult.success();

    }
}
